(function () {

    var myChart = echarts.init(document.querySelector(".tab_dis .dis .dis_a1"))


    $.get('/test2').done(function (data) {
        data = JSON.parse(data)
        var option = ({
            title: {
                text: '计算机专业薪水前10岗位'
            },
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'shadow'
                }
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: [
                {
                    type: 'category',
                    data: data.key,
                    axisTick: {
                        alignWithLabel: true
                    },
                    // axisLabel: {//坐标轴刻度标签的相关设置。
                    //     interval: 0,
                    //     rotate: "45"
                    // },
                    axisLabel: {//坐标轴刻度标签的相关设置。
                        formatter: function (params) {
                            var newParamsName = "";// 最终拼接成的字符串
                            var paramsNameNumber = params.length;// 实际标签的个数
                            var provideNumber = 4;// 每行能显示的字的个数
                            var rowNumber = Math.ceil(paramsNameNumber / provideNumber);// 换行的话，需要显示几行，向上取整
                            /**
                             * 判断标签的个数是否大于规定的个数， 如果大于，则进行换行处理 如果不大于，即等于或小于，就返回原标签
                             */
                            // 条件等同于rowNumber>1
                            if (paramsNameNumber > provideNumber) {
                                /** 循环每一行,p表示行 */
                                for (var p = 0; p < rowNumber; p++) {
                                    var tempStr = "";// 表示每一次截取的字符串
                                    var start = p * provideNumber;// 开始截取的位置
                                    var end = start + provideNumber;// 结束截取的位置
                                    // 此处特殊处理最后一行的索引值
                                    if (p == rowNumber - 1) {
                                        // 最后一次不换行
                                        tempStr = params.substring(start, paramsNameNumber);
                                    } else {
                                        // 每一次拼接字符串并换行
                                        tempStr = params.substring(start, end) + "\n";
                                    }
                                    newParamsName += tempStr;// 最终拼成的字符串
                                }

                            } else {
                                // 将旧标签的值赋给新标签
                                newParamsName = params;
                            }
                            //将最终的字符串返回
                            return newParamsName
                        }

                    },
                }
            ],
            yAxis: [
                {
                    type: 'value',
                    axisLabel: {
                    show: true,
                    interval: 'auto',
                    formatter: '{value}(k)'
                },
                show: true


                }
            ],
            series: [
                {
                    name: 'Direct',
                    type: 'bar',
                    barWidth: '60%',
                    data: data.value,
                }
            ]
        });
        myChart.setOption(option)

        window.addEventListener("resize", function () {
            myChart.resize()
        })
    })

})();
(function () {

    var tab = document.querySelector('.tab');
    var lis = tab.querySelectorAll('.tabs li');
    var dis = document.querySelectorAll('.dis');
    for (var i = 0; i < lis.length; i++) {
        lis[i].setAttribute('index', i);
        lis[i].onclick = function () {

            for (var i = 0; i < lis.length; i++) {
                lis[i].className = '';
            }

            this.className = 'current';
            var index = this.getAttribute('index');
            for (var i = 0; i < dis.length; i++) {
                dis[i].style.display = 'none';
            }
            dis[index].style.display = 'block';
        }
    }


})();
(function () {

    var myChart = echarts.init(document.querySelector(".tab_dis .dis .dis_b1"))
    $.get('/test2').done(function (data) {
        data = JSON.parse(data)
        var data_new = []
        for (var i = 0; i < data.key.length; i++) {
            var obj = new Object()
            obj.value = data.value[i]
            obj.name = data.key[i]
            data_new[i] = obj

        }
        // console.log(data_new)
        var option = {
            legend: {
                top: 'bottom'
            },
            toolbox: {
                show: true,
                feature: {
                    mark: {show: true},
                    dataView: {show: true, readOnly: false},
                    restore: {show: true},
                    saveAsImage: {show: true}
                }
            },
            series: [
                {
                    name: 'Nightingale Chart',
                    type: 'pie',
                    radius: [50, 250],
                    center: ['50%', '50%'],
                    roseType: 'area',
                    itemStyle: {
                        borderRadius: 8
                    },
                    data: data_new

                }
            ]
        };
        myChart.setOption(option)

        window.addEventListener("resize", function () {
            myChart.resize()
        })
    })

})();
(function () {
    var myChart = echarts.init(document.querySelector(".tab_dis .dis .dis_b2"))
    $.get('/test2').done(function (data) {
        data = JSON.parse(data)
        var data_new = []
        for (var i = 0; i < data.key.length; i++) {
            var obj = new Object()
            obj.value = data.value[i]
            obj.name = data.key[i]
            data_new[i] = obj

        }
        var option = {
            tooltip: {
                trigger: 'item'
            },
            legend: {
                top: '5%',
                left: 'center'
            },
            series: [
                {
                    name: 'Access From',
                    type: 'pie',
                    radius: ['40%', '70%'],
                    avoidLabelOverlap: false,
                    itemStyle: {
                        borderRadius: 10,
                        borderColor: '#fff',
                        borderWidth: 2
                    },
                    label: {
                        show: false,
                        position: 'center'
                    },
                    emphasis: {
                        label: {
                            show: true,
                            fontSize: '40',
                            fontWeight: 'bold'
                        }
                    },
                    labelLine: {
                        show: false
                    },
                    data: data_new
                }
            ]
        };
        myChart.setOption(option)

        window.addEventListener("resize", function () {
            myChart.resize()
        })
    })

})();
(function () {
    var myChart = echarts.init(document.querySelector(".tab_dis .dis .dis_c2"))
    $.get('/test3').done(function (data) {
        data = JSON.parse(data)
        var data_value_max = []
        var data_value_min = []
        for (var i = 0; i < data.value.length; i++) {
            data_value_max[i] = data.value[i][0]
            data_value_min[i] = data.value[i][1]
        }
        var option = {
            title: {
                text: '岗位最低和最高月薪'
            },
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'shadow'
                }
            },
            legend: {},
            grid: {
                left: '10%',
                right: '10%',
                bottom: '10%',
                containLabel: true
            },
            xAxis: {
                type: 'value',
                boundaryGap: [0, 0.01]
            },
            yAxis: {
                type: 'category',
                data: data.key
            },
            series: [
                {
                    name: '最高月薪(k)',
                    type: 'bar',
                    data: data_value_max
                },
                {
                    name: '最低月薪(k)',
                    type: 'bar',
                    data: data_value_min
                }
            ]
        };
        myChart.setOption(option)

        window.addEventListener("resize", function () {
            myChart.resize()
        })
    })


})();
(function () {
    var myChart = echarts.init(document.querySelector(".tab_dis .dis .dis_c1"))


    $.get('/test2').done(function (data) {
        data = JSON.parse(data)
        var option = ({
            title: {
                text: '计算机专业薪水前10岗位'
            },
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'shadow'
                }
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: [
                {
                    type: 'category',
                    data: data.key,
                    axisTick: {
                        alignWithLabel: true
                    },
                    // axisLabel: {//坐标轴刻度标签的相关设置。
                    //     interval: 0,
                    //     rotate: "45"
                    // },
                    axisLabel: {//坐标轴刻度标签的相关设置。
                        formatter: function (params) {
                            var newParamsName = "";// 最终拼接成的字符串
                            var paramsNameNumber = params.length;// 实际标签的个数
                            var provideNumber = 4;// 每行能显示的字的个数
                            var rowNumber = Math.ceil(paramsNameNumber / provideNumber);// 换行的话，需要显示几行，向上取整
                            /**
                             * 判断标签的个数是否大于规定的个数， 如果大于，则进行换行处理 如果不大于，即等于或小于，就返回原标签
                             */
                            // 条件等同于rowNumber>1
                            if (paramsNameNumber > provideNumber) {
                                /** 循环每一行,p表示行 */
                                for (var p = 0; p < rowNumber; p++) {
                                    var tempStr = "";// 表示每一次截取的字符串
                                    var start = p * provideNumber;// 开始截取的位置
                                    var end = start + provideNumber;// 结束截取的位置
                                    // 此处特殊处理最后一行的索引值
                                    if (p == rowNumber - 1) {
                                        // 最后一次不换行
                                        tempStr = params.substring(start, paramsNameNumber);
                                    } else {
                                        // 每一次拼接字符串并换行
                                        tempStr = params.substring(start, end) + "\n";
                                    }
                                    newParamsName += tempStr;// 最终拼成的字符串
                                }

                            } else {
                                // 将旧标签的值赋给新标签
                                newParamsName = params;
                            }
                            //将最终的字符串返回
                            return newParamsName
                        }

                    },
                }
            ],
            yAxis: [
                {
                    type: 'value',
                    axisLabel: {
                    show: true,
                    interval: 'auto',
                    formatter: '{value}(k)'
                },
                show: true

                }
            ],
            series: [
                {
                    name: 'Direct',
                    type: 'bar',
                    barWidth: '60%',
                    data: data.value,
                }
            ]
        });
        myChart.setOption(option)

        window.addEventListener("resize", function () {
            myChart.resize()
        })
    })

})();
(function () {
    var myChart = echarts.init(document.querySelector(".tab_dis .dis .dis_d1"))
    $.get('/test4').done(function (data) {
        data = JSON.parse(data)
        console.log(data)
        data_list = []
        i = 0
        for (var Key in data) {
            var obj = new Object()
            obj.value = data[Key]
            obj.name = Key
            data_list[i] = obj
            i = i + 1

        }
        option = {
            title: {
                text: '计算机行业的学历统计'
            },
            tooltip: {
                trigger: 'item'
            },
            legend: {
                top: '5%',
                left: 'center'
            },
            series: [
                {
                    name: 'Access From',
                    type: 'pie',
                    radius: ['40%', '70%'],
                    avoidLabelOverlap: false,
                    label: {
                        show: false,
                        position: 'center'
                    },
                    emphasis: {
                        label: {
                            show: true,
                            fontSize: '40',
                            fontWeight: 'bold'
                        }
                    },
                    labelLine: {
                        show: false
                    },
                    data: data_list
                }
            ]
        };
        myChart.setOption(option)

        window.addEventListener("resize", function () {
            myChart.resize()
        })
    })

})();
(function () {
    var myChart = echarts.init(document.querySelector(".tab_dis .dis .dis_d2"))
    $.get('/salaryEducation').done(function (data) {
        data = JSON.parse(data)
        var option = {
            title: {
                text: '经验与（最高）薪水的关系'
            },
            xAxis: {
                type: 'category',
                data: data.key
            },
            yAxis: {
                type: 'value',
                axisLabel: {
                    show: true,
                    interval: 'auto',
                    formatter: '{value}(k)'
                },
                show: true
            },
            series: [
                {
                    data: data.value,
                    type: 'bar',
                    showBackground: true,
                    backgroundStyle: {
                        color: 'rgba(180, 180, 180, 0.2)'
                    }
                }
            ]
        };
        myChart.setOption(option)

        window.addEventListener("resize", function () {
            myChart.resize()
        })
    })

})();